package cn.tedu._05mvcboot01.controller;

import cn.tedu._05mvcboot01.controller.pojo.dto.WeChatDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

@Controller
public class UserController {
    @RequestMapping(value = "v1/users/login")
    @ResponseBody
    public String login() {
        return "恭喜你,登录成功";
    }

    /**HttpServletRequest接收*/
    @RequestMapping(value = "v1/users/reg")
    @ResponseBody
    public String reg(HttpServletRequest request) {
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        return username + "-" + password;
    }

    /**
     * 1.修改密码功能接口说明:
     * 地址: /v1/users/changepwd
     * 查询参数: username  newpassword
     * 返回响应:username-newpassword
     * 2.服务端接受数据的方式 2:通过声明参数方式接受
     * http://localhost:8080/v1/users/changepwd?username=xxx&newpwd=xxx
     */
    @RequestMapping(value = "/v1/users/changepwd")
    @ResponseBody
    public String changepwd(String username, String newpassword) {

        return username + "-" + newpassword;
    }

    /**
     * DTO 类方式接收
     * 1.功能:第三方微信登录功能
     *      1.1请求URL地址:/v1/users/WeChat
     *      1.2查询参数:?name=微信号&pwd=密码
     *      1.3返回响应:微信号"密码
     *      http://localhost:8080/v1/users/WeChat?name=微信号&pwd=密码
     */
    @RequestMapping("/v1/users/WeChat")
    @ResponseBody
    public String WeChat(WeChatDTO weChatDTO){
        String name = weChatDTO.getName();
        String pwd = weChatDTO.getPwd();
        return name+"-"+pwd;
    }

}
